<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="renderer" content="webkit">
  <meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width">
  <title>${webName}-${webTitle}</title>
  <meta name="keywords" content="${meta_keys!}">
  <meta name="description" content="${meta_desc!}">
  <meta name="applicable-device" content="pc,mobile"/>
  <meta http-equiv="Cache-Control" content="no-transform"/>
  <% include("layout/headercss.html"){} %>
  <link rel="stylesheet" href="${version('/static/theme/reg.css')}">

</head>
<body class="home blog el-boxed">
<% include("layout/header.html"){} %>
<div class="">
  <div class="header_content">
    <div class="reg-form">
      <div class="reg-action">
        <% if(isNotEmpty(canReg) && canReg) { %>
        <div class="title">用户注册</div>
        <div class="item">
          <label>用户名</label>
          <input type="text" name="username" placeholder="请输入用户名"/>
        </div>
        <div class="item">
          <label>邮箱</label>
          <input type="text" name="email" placeholder="请输入邮箱"/>
        </div>
        <div class="item">
          <label>密码</label>
          <input type="password" name="password" placeholder="请输入密码"/>
        </div>
        <div class="item">
          <label>确认密码</label>
          <input type="password" name="passwordAgain" placeholder="请再次输入密码"/>
        </div>
        <div class="btn" id="btn-reg">注册</div>
        <% } else { %>
        <div class="forbid-reg"><b>网站已关闭注册</b></div>
        <% } %>
      </div>
    </div>
  </div>
</div>

<% include("layout/footer.html"){} %>
<script>
  $(function () {
    $("#btn-reg").click(function () {
      if (!$("input[name='username']").val()){
        toastUtil.error("请输入用户名")
        return
      }
      if (!$("input[name='email']").val()){
        toastUtil.error("请输入邮箱")
        return
      }
      if (!$("input[name='password']").val()){
        toastUtil.error("请输入密码")
        return
      }
      if (!$("input[name='passwordAgain']").val()){
        toastUtil.error("请输入确认密码")
        return
      }
      $.ajax({
        url: "/user/reg",
        type: "post",
        contentType: "application/json",
        data: JSON.stringify({
          username: $("input[name='username']").val(),
          email: $("input[name='email']").val(),
          password: $("input[name='password']").val(),
          passwordAgain: $("input[name='passwordAgain']").val()
        }),
        dataType: "json",
        success: function(data) {
          toastUtil.success("注册成功")
          location.href="/"
        },
        error: function (resp){
          const data = JSON.parse(resp.responseText);
          toastUtil.error(data.msg)
        }
      });
    });
  })
</script>
</body>
</html>
